package Clases;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;


public class Pruebas {
	
	final static int calibrar = 50;
	static ArrayList<Float> aceleracion = new ArrayList<Float>();
	static float offset = 0;
	
	public static void main(String [] args) throws IOException{
		File archivo = new File("/home/bonzjame/prueba_sd.txt");
		FileReader fr = new FileReader(archivo);
		BufferedReader br = new BufferedReader(fr);
		float [] x = new float[1000];
		int index = 0;
		String linea = null;
		while((linea = br.readLine()) != null){
			x[index] = Float.parseFloat(linea);
			index++;
			//if(index == 63) calibrar(x);
		}
		x[index] = 99999999;
		fr.close();
		tratar(x);
		float off = offset;
		System.out.println(aceleracion.toString());
	}
	
	public static void calibrar(float [] val){
		for(int i = 0; i < 64; i++){
			offset += val[i];
		}
		offset = (float) (offset/64.);
	}
	
	public static void tratar(float [] val){
		boolean calibrar = true;
		for(int i = 0; val[i] != 99999999; i++){
			if(calibrar){
				calibrar(val);
				i = 63;
				calibrar = false;
			}
			else integrar(val[i]);
		}
	}
	
	public static void integrar(float num){
		num = num - offset;
		num = (float) (num*(3.3/(1023*0.800)));
		aceleracion.add(num);
	}
}
